package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {
    @AutoFill(OperationType.INSERT)
    @Insert("insert into category (id, type, name, sort, status, create_user, update_user,create_time,update_time) values (#{id},#{type},#{name},#{sort},#{status},#{createUser},#{updateUser},#{createTime},#{updateTime})")
    void savecategory(Category category);

    Page<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);

//    @AutoFill(OperationType.UPDATE)
//    @Update("update category set status=#{status} ,update_time=#{updateTime} where id=#{id}")
//    void status(int status, Long id);

    @AutoFill(OperationType.UPDATE)
    @Update("update category set id=#{id}, type=#{type}, name=#{name}, sort=#{sort},update_user=#{updateUser},update_time=#{updateTime},status=#{status} where id=#{id}")
    void update(Category category);

    @Delete("delete from category where id=#{id}")
    void delete(Long id);

    @Select("select * from category where id = #{id}")
    Category selectById(Long id);
    @Select("select * from category")

    List<CategoryDTO> list();

    @Select("select * from category where type = #{type}")
    List<Category> selectByType(Long type);

    @Select("select * from category")
    List<Category> all();
}
